/*
 * @Date: 2023-03-10 14:43:48
 * @LastEditors: Zireael 1193875164@qq.com
 * @LastEditTime: 2023-03-10 14:45:11
 * @FilePath: \A19\backend\src\api\Get\ApiGetCourseStus.ts
 */
import { ApiCall } from "tsrpc";
import {
  ReqGetCourseStus,
  ResGetCourseStus,
} from "../../shared/protocols/Get/PtlGetCourseStus";
import { Global } from "../../Global/index";
import { ObjectId } from "mongodb";
import { users } from "../../shared/types/user";

export default async function (
  call: ApiCall<ReqGetCourseStus, ResGetCourseStus>
) {
  // TODO
  const ret = await Global.collection("selectCourses")
    .aggregate([
      {
        $match: {
          course: call.req.course,
        },
      },
      {
        $lookup: {
          from: "users",
          localField: "student",
          foreignField: "_id",
          as: "student",
        },
      },
    ])
    .toArray();

    call.succ({
        stus:ret as {
            _id:ObjectId,
            student:users[],
            course:ObjectId
          }[]
    })
}
